﻿package {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.net.navigateToURL;
	
	import laan.xiaonei.XiaoNeiAPIEvent;
	import laan.xiaonei.XiaoNeiAPI;
	
	public class ScrollBarAS3 extends Sprite {
		public var my_scrollbar:MakeScrollBar;
		private var api:XiaoNeiAPI;
		private var msg:String = "hello !! --rayYee"
		private var feed_title:String = '{"doWhat":"aaa", "actor":"rayYee"}';
		private var feed_body:String = '{"content":"bbb"}';
		public function ScrollBarAS3() 
		{				
			addEventListener(Event.ADDED_TO_STAGE, onGameAddStageHandler); 	
		}		
		private function onGameAddStageHandler(e:Event):void
		{			
			removeEventListener(Event.ADDED_TO_STAGE, onGameAddStageHandler);
			initialData();			
		}
		private function initialData()
		{
			txt1.buttonLable = "getLoginUser"
			txt2.buttonLable = "getAppAdded"
			txt3.buttonLable = "getFriendsUID"
			txt4.buttonLable = "getUserInfo"
			txt5.buttonLable = "getFriendsDetail"
			txt6.buttonLable = "getAppFriends"
			txt7.buttonLable = "getAppFriendsAll"
			txt8.buttonLable = "sendNotification";
			txt9.buttonLable = "sendFeed";
			txt10.buttonLable = "registerOrder";
			txt11.buttonLable = "checkOrder";
			
			txt1.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt2.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt3.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt4.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt5.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt6.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt7.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt8.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt9.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt10.addEventListener(MouseEvent.MOUSE_DOWN,onbtnDown)
			txt11.addEventListener(MouseEvent.MOUSE_DOWN, onbtnDown)
			
			scroll_txt.text = "";
			my_scrollbar = new MakeScrollBar( scroll_mc, scroll_text );
			
			start()
		}
		
		private function onbtnDown(e:MouseEvent):void {
			switch (e.currentTarget.buttonLable) {
				case "getLoginUser":
					api.getLoginUser(callHandler)
				break;
				case "getAppAdded":
					api.getAppAdded(callHandler);
				break;
				case "getFriendsUID":
					api.getFriendsUID(callHandler)
				break;
				case "getUserInfo":
					api.getUserDetail(callHandler, api.uid)
				break;
				case "getFriendsDetail":
					api.getFriendsDetail(callHandler)
				break;
				case "getAppFriends":
					api.getAppUsers(callHandler)
				break;
				case "getAppFriendsAll":
					api.getAppUsers(callHandler, true)
				break;
				case "sendNotification":
					api.sendNotification(callHandler, null, msg)
				break;
				case "sendFeed":
					api.sendFeed(callHandler, 1, feed_title, feed_body)
				break;
				case "registerOrder":
					api.registerOrder(callHandler, "234256", 40, "fefefefhao")
				break;
				case "checkOrder":
					api.checkOrderCompleted(callHandler, "234256")
				break;
				}
		}

		private function start():void {
			api = new XiaoNeiAPI("111111111111111111", "222222222222222222222222222");//apiKey:String, secretKey:String
			api.addEventListener(XiaoNeiAPIEvent.API_READY, apiReadyHandler);
			api.toLogin()
			//api.initAPI("224888250", "2.4fcd45080c9ea19aa062bb4b8af36294.3600.1264068000-224888250");//uid:String, session:String
		}

		private function apiReadyHandler(event:Event):void {

		}
			
		private function callHandler(obj:Object):void {
			for (var i:String in obj) {
				trace(obj[i])
				scroll_txt.text += i + ":" + obj[i] + "\r"
			}
			//scroll_txt.text += "\r\r";
		}

		public function scroll_text( n:Number ) {
			//trace( "????" );
			scroll_txt.scrollV = Math.round( ( scroll_txt.maxScrollV - 1 ) * n ) + 1;
		}
	}
}